package com.suse.jd_system_server.service.impl;

import com.fasterxml.jackson.databind.JsonNode;
import com.suse.jd_system_server.dao.DatasourceInitDao;
import com.suse.jd_system_server.utils.BaiduMapUtil;
import com.suse.jd_system_server.utils.DataInitUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 数据初始化服务
 */
@Service
public class DatasourceInitServiceImpl {
    @Autowired
    private DatasourceInitDao datasourceInitDao;
    /**
     * 添加酒店数据
     * 由于日配额有限，直接根据code查取部分数据即可
     * code:33-373
     */
    public void insertHotelData(String code) throws Exception {
        JsonNode addr = BaiduMapUtil.getAddr("酒店",code);
        DataInitUtil dataInitUtil = new DataInitUtil();
        dataInitUtil.insertHotelData(addr);
    }

    /**
     * 添加图片数据
     * code：1酒店0房间，方便管理员指定外键
     * @param s，图片url地址字符串
     */
    public void inserImgData(String s){
        String[] strings = s.split("\n");
        for (String str:strings) {
            datasourceInitDao.imgInsert(str,0);
        }
    }

    /**
     * 修改单表单字段信息
     * @param str1,str2，待修改字段名
     * @param value，修改值
     * @param condition，修改条件
     */
    public <T>void setSingleColumnBySingleCondition(String str1,String str2,T value,T condition){
        datasourceInitDao.setSingleColumnBySingleCondition(str1,str2,value,condition);
    }
}
